﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using Business;

namespace BaseWeb
{
    public partial class Tree_test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindMenu();
            }
        }

        private void BindMenu()
        {
            List<li_Menu> arryMenu = CommonSystem.Instance.Service.GetListByWhere<li_Menu>(c => c.ParentKeyId == "0").OrderBy(c => c.OrderIndex).ToList();
            foreach (var enMenu in arryMenu)
            {
                //生成主按钮
                System.Web.UI.HtmlControls.HtmlGenericControl TopDiv = new System.Web.UI.HtmlControls.HtmlGenericControl();
                TopDiv.TagName = "div";
                TopDiv.ID = "MainDiv_" + enMenu.KeyId;
                TopDiv.InnerText = TopDiv.InnerHtml = enMenu.Name;
                TopDiv.Attributes.Add("class", "menu");
                divBody.Controls.Add(TopDiv);
                //生成panel
                System.Web.UI.HtmlControls.HtmlGenericControl panelDiv = new System.Web.UI.HtmlControls.HtmlGenericControl();
                panelDiv.TagName = "div";
                panelDiv.ID = "PenelDiv_" + enMenu.KeyId;
                panelDiv.Attributes.Add("class", "panel");
                divBody.Controls.Add(panelDiv);
                //在panel里添加链接
                BindChild(panelDiv, enMenu.KeyId);
            }
        }


        private void BindChild(System.Web.UI.HtmlControls.HtmlGenericControl parentDiv, string parentKeyId)
        {
            List<li_Menu> arryMenu = CommonSystem.Instance.Service.GetListByWhere<li_Menu>(c => c.ParentKeyId == parentKeyId).OrderBy(c => c.OrderIndex).ToList();
            foreach (var enMenu in arryMenu)
            {
                System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl();
                div.TagName = "div";
                div.ID = "div_btn_" + enMenu.KeyId;
                div.InnerText = enMenu.Name;
                string jstring = string.Format("window.open('{0}','WorkFrame')", enMenu.Url);
                div.Attributes.Add("onclick", jstring);
                div.Attributes.Add("class", "common");
                parentDiv.Controls.Add(div);
            }
        }


    }
}
